package com.zegome.game.gomestory.main;

import java.util.ArrayList;
import java.util.Vector;

import aurelienribon.tweenengine.TweenManager;

import com.badlogic.gdx.physics.box2d.joints.PulleyJoint;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent;
import com.ironsource.mobilcore.CallbackResponse;
import com.ironsource.mobilcore.MobileCore;
import com.ironsource.mobilcore.CallbackResponse.TYPE;
import com.zegome.game.gomestory.MainActivity;
import com.zegome.game.gomestory.main.helper.AndroidHelper;
import com.zegome.game.gomestory.main.helper.GiftRequest;
import com.zegome.game.gomestory.main.helper.IMAction;
import com.zegome.game.gomestory.main.helper.IOHelper;
import com.zegome.game.gomestory.main.helper.StageHelper;
import com.zegome.game.gomestory.main.helper.StringHelper;
import com.zegome.game.gomestory.main.libs.AutoRunText;
import com.zegome.game.gomestory.main.scene.BaseGameScreen;
import com.zegome.game.main.AndroidGameController;
import com.zegome.game.util.helper.SettingManager;
import com.zegome.game.util.helper.input.InputTextAndroid;

public class Center {
	
	 public Vector<GiftRequest> mGiftRequests;
	
	
	public GomeController controller;
	// Helper
	
	public AndroidHelper androidHelper;
	public StageHelper stageHelper;
	
	// Utils
	public StringHelper stringHelper;
	public IOHelper ioHelper;
	
	// 
	public LangText lang;
	public A a;
	public D d;
	public G g;
	
	// KeyBoard
	public InputTextAndroid inputTextAndroid;
	public AutoRunText autoRunText;
	public SettingManager settingManager;
	
	public Center(){
		// Helper
				androidHelper = new AndroidHelper(this);
				stageHelper = new StageHelper(this);
				// Utils
				stringHelper = new StringHelper();
				ioHelper = new IOHelper();
				// 
				lang = new LangText(this);				
				a = new A(this);
				d = new D(this);
				g = new G(this);
				//
				autoRunText = new AutoRunText(this,new Actor());
				autoRunText.setXY(100, 0);
				autoRunText.setWH(600, 40);
				//
				androidHelper.initFolderAvatar();
				
				mGiftRequests = new Vector<GiftRequest>();		
	}
	
	public void addSettingManager(final BaseGameScreen screen,final Stage stage,final TweenManager tweenManager){				
		if(settingManager != null)
		{
			settingManager.init(stage, tweenManager);
			settingManager.build();			
			return;
		}
			settingManager = new SettingManager();
			settingManager.init(stage, tweenManager);
			settingManager.setStyle(SettingManager.TO_RIGHT);
			settingManager.setSize(66, 66);
			settingManager.setPad(5);
			settingManager.setXY(0, -5);
			
			Image iconSetting=null;
			ImageButton setting = null, music=null, sound=null, info=null, help=null;
			
			if (setting == null) {
				setting = stageHelper.createImageButton(g.mSkin, a.blankSmallButton,
						null, null,  (731), (480-215),66,66);
				iconSetting = stageHelper.createImage(a.settingIcon, 6, 5,50,49);
				iconSetting.setOrigin(25, 25);				
				settingManager.addActor(setting,null);
				settingManager.setRotateImage(iconSetting);
			}
			
			if (music == null) {
				music = stageHelper.createImageButton(g.mSkin, a.friendNorRegion,
						a.friendPressRegion, null, 0, 0);
				settingManager.addActor(music,
				new ChangeListener() {
					@SuppressWarnings("synthetic-access")
					@Override
					public void changed(ChangeEvent event, Actor actor) {
						if(a.isHasDialog() == true)
							return;						
						d.isMusic = !d.isMusic;
						a.soundOnOff();
						a.yesSound.play(a.vls);											
					}
				}
				);
			}
			
			if (sound == null) {
				sound = stageHelper.createImageButton(g.mSkin, a.exitNorRegion,
						a.exitPressRegion, null,  (731), (480-282));
				settingManager.addActor(sound,
				new ChangeListener() {
					@SuppressWarnings("synthetic-access")
					@Override
					public void changed(ChangeEvent event, Actor actor) {
						if(a.isHasDialog() == true)
							return;
						d.isSound = !d.isSound;
						a.soundOnOff();
						a.yesSound.play(a.vls);					
					}
				});
			}
			
			
			if (info == null) {
				info = stageHelper.createImageButton(g.mSkin, a.infoNorRegion,
						a.infoPressRegion, null, (731), (480-84));		
				settingManager.addActor(info,
				new ChangeListener() {
					@SuppressWarnings("synthetic-access")
					@Override
					public void changed(ChangeEvent event, Actor actor) {
						if(a.isHasDialog() == true)
							return;
						a.yesSound.play(a.vls);
						//stageHelper.createDialogLoseVS2(stage, tweenManager, "phu2810", "thiennx", 20, 10, 1, 20, null, null);
						//stageHelper.createDialogWinVS(stage, tweenManager, "phu2810", "thiennx", 12, 13, 10, 11, null, null, null);
						stageHelper.createDialog(stage, tweenManager,lang.dialogInfo, 1, null, null);
						//stageHelper.createDialogWinVS(stage, tweenManager, "Phubka", null, 1, 3, 2, 5, null, null, null);
						//androidHelper.sendBonusExp(stage, tweenManager);
						//stageHelper.createDialogKK(stage, tweenManager);
					}
				}
				);
			}
			
			if (help == null) {
				help = stageHelper.createImageButton(g.mSkin, a.sharedNorRegion,
						a.sharedPressRegion, null,  (731), (480-150));
				settingManager.addActor(help,
				new ChangeListener() {
					@Override
					public void changed(ChangeEvent event, Actor actor) {
						if(a.isHasDialog() == true)
							return;
						stageHelper.createDialogHelpML(stage, tweenManager);			
						//stageHelper.createDialogLoseVS2(stage, tweenManager, "phu2810", "12345", 1, 2, 3, 4, null, null);
					}
				});
			}
					
			settingManager.build();
	}
	long lastime_show_mobile_core;
	public boolean showMobileCore(final IMAction action){		
		if(MainActivity.isMC){
		if(System.currentTimeMillis() - lastime_show_mobile_core> 300000){
		MobileCore.showOfferWall(controller.getActivity(), new CallbackResponse() {
			
			@Override
			public void onConfirmation(TYPE arg0) {
				// TODO Auto-generated method stub
				if(action!=null)
					action.action();
			}
		});
		lastime_show_mobile_core = System.currentTimeMillis();
		return true;
		}
		return false;
		}
		return false;
	}
}
